package com.ktjy.springsecuritydemo.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {
    @GetMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @PostMapping("/doLogin")
    public String login(){
        System.out.println("执行登录方法");
        return "main";
    }

   // @Secured("ROLE_abc")
    @PreAuthorize("hasRole('abc')")
    @RequestMapping("/toMain")
    public String toMain(){
        return "main";
    }

    //负责登录失败后跳转失败页面
    @RequestMapping("/toError")
    public String toError(){
        return "error";
    }

    @GetMapping("/Main1")
    public String Main1(){
        return "main1";
    }

    @RequestMapping("/demo")
    public String demo(){
        return "demo";
    }
}
